# -*- coding:UTF-8 -*-
import zlib, hashlib, struct

class cMyChksum():
	'''
	return value is string
	'''
	def __init__(self, data):
		self.data = data
		
	def crc32(self):
		crc32 = zlib.crc32(self.data, 0) & 0xffffffff
		return "0x%08X" % (crc32)
	
	def adler32(self):
		adler32 = zlib.adler32(self.data) & 0xffffffff
		return "0x%08X" % (adler32)
	
	def md5(self):
		m = hashlib.md5()
		m.update(self.data)
		return m.hexdigest().upper()
	
	def sha1(self):
		m = hashlib.sha1()
		m.update(self.data)
		return m.hexdigest().upper()		
	
	def sum(self):
		s = 0
		#for c in self.data:	s += ord(c)
		fmt = "%dB" % len(self.data)
		bytes = struct.unpack_from(fmt, self.data)
		for x in bytes:
			s += x;
		return "0x%08X" % s

def main():
	'''
	examples
	'''
	buf = file(sys.argv[1],"rb").read()
	print "%s" % cMyChksum(buf).crc32()
	print "%s" % cMyChksum(buf).adler32()
	print "%s" % cMyChksum(buf).md5()
	print "%s" % cMyChksum(buf).sha1()
	print "%s" % cMyChksum(buf).sum()
	
if __name__ == "__main__":
	import sys
	main()
